<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" href="css/front.css" rel="stylesheet" />
<link type="text/css" href="css/main.css" rel="stylesheet" />
<link type="text/css" href="css/home.css" rel="stylesheet" />
<link href="css/alert.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="css/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="common/JsSupport.js"></script>
<title>记账本</title>
</head>
<body>

	<div>
		<s:form id="editForm">
			<table>
				<tr style="display: none;">
					<td>分类id：</td>
					<td><s:textfield name="account.id" theme="simple" id="accountId" />
					</td>
				</tr>
				<tr>
					<td><span style="color: red">*</span>名称：</td>
					<td><s:textfield theme="simple" name="account.accountName" id="accountName" cssClass="txt_input" class='theme' />
					</td>
				</tr>
				<tr>
					<td><span style="color: red">*</span>币种：</td>
					<td><select id="currency" name="account.currency.id">
							<s:iterator value="currencyList">
								<option value='<s:property value="id"/>'>
									<s:property value="contentName" />
								</option>
							</s:iterator>
					</select></td>
				</tr>
				<tr>
					<td><input type="button" id="submit" value="提交" class='theme' />
					</td>
					<td><input type="button" id="close" value="关闭" class='theme' />
					</td>
				</tr>
			</table>
		</s:form>
	</div>

</body>
<script type="text/javascript">
	$(function() {
		var id = $.query.get('id');
		getAccountData(id);
		/**
		 * 提交
		 */
		$('#submit').click(
				function() {
					$.ajax({
						 type : "POST",
						 url : 'updateAccount.do',
						 data : $('#editForm').serialize(),//{'account.id' : id,'account.accountName' : name,'account.currency.id':currencyId},//
						 dataType : 'json',
						 success : function(response, ioArgs) {
							 window.parent.updateData(response.OPERATOR_RESULT);
// 							 accountList.query({
// 									click : false
// 								});
// 							 hiOverAlert(response.OPERATOR_RESULT);
							
						}
					});
					
					
// 					window.parent.updateData($("#accountId").val(), $(
// 							'#accountName').val(), $('#currency').val());
				});

		$('#close').click(function() {
			window.parent.closeEditAccountDialog();
		});

	});
	/**
	 * 获取账户数据
	 */
	function getAccountData(id) {
		$.ajax({ type : "POST", url : 'getAccountById.do',
			data : { 'id' : id }, dataType : 'json',
			success : function(response, ioArgs) {
				var account = response.account;
				$('#accountId').val(account.id);
				$('#accountName').val(account.accountName);
				$('#currency').val(account.currency.id);

			} });
	}
</script>
</html>